package com.health.personal.controller;

import com.health.common.core.domain.R;
import com.health.common.core.web.domain.AjaxResult;
import com.health.common.security.utils.SecurityUtils;
import com.health.common.core.po.TuserPo;
import com.health.personal.domain.dto.RegisterRetrieveDto;
import com.health.personal.domain.dto.RetrievePwdDto;
import com.health.personal.service.TUserService;
import com.health.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @BelongsProject: dimensionality-manage
 * @BelongsPackage: com.health.personal.controller
 * @Author: 许力匀
 * @CreateTime: 2024-12-12  19:54
 * @Description: 患者表控制层
 * @Version: 1.0
 */
@RestController
@RequestMapping("TUser")
public class TuserController {

    @Autowired
    private TUserService tUserService ;

    /**
     * 通过邮件查询患者信息
     */
    @GetMapping("findTUser/{email}")
    public R<LoginUser> selectByEmail(@PathVariable("email") String email)
    {
        TuserPo tUser = tUserService.selectByEmail(email);
        LoginUser loginUser = new LoginUser();
        loginUser.setTuserPo(tUser);
        return  R.ok(loginUser);
    }

    /**
     * 获取患者登录信息
     *
     */
    @GetMapping("getInfo")
    public AjaxResult getInfo()
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        AjaxResult ajax = AjaxResult.success();
        ajax.put("user", loginUser.getTuserPo());
        return  ajax;
    }

    /**
     * 发送验证码
     */
    @GetMapping("sendCaptcha/{email}")
    public R<String>  sendCaptcha(@PathVariable("email") String email)
    {
        tUserService.sendCaptcha(email);
        return   R.ok("已发送");
    }

    /**
     * 修改患者端密码
     */
    @PostMapping("updUserPwd")
    public R<String> updUserPwd(@RequestBody RetrievePwdDto retrievePwdDto)
    {
        tUserService.updatePassword(retrievePwdDto.getEmail(),retrievePwdDto.getPassword(),retrievePwdDto.getCode(),retrievePwdDto.getBeginPassword());
        return  R.ok("修改成功");
    }

    /**
     *患者注册
     */
    @PostMapping("register")
    public R<String> register(@RequestBody RegisterRetrieveDto registerRetrieveDto)
    {
        tUserService.register(registerRetrieveDto);
        return  R.ok("注册成功");
    }
}
